package edu.towson.cosc.cosc455.pjemmott;

import java.util.*;
import java.io.*;

public class mycompiler {
	static String token;
	static File filename;

	/**
	 * @param args
	 */
	// todo
	// build stack(s)
	// output to file

	// Main runner begins program
	
	public static void main(String[] args) throws CompilerException {
		PaulSyntaxAnalyzer taxer = new PaulSyntaxAnalyzer();

		MyLexicalAnalyzer lexer = new MyLexicalAnalyzer();

		// colllects file
		// and converts to single string
		filename = new File(args[0]);

		if (filename.getName().endsWith(".mkd")) {

			try {
				Scanner scan = new Scanner(filename);

				token = "";
				while (scan.hasNextLine()) {
					token += scan.nextLine() + " ";

				}
				Scanner scan2 = new Scanner(token);
				// end conversion

				// calls Beginning of Lexical & Syntax Analysis
				try {
					lexer.s.push("#START DOCUMENT");
					taxer.document(lexer.getNextToken(token));
					
				} catch (CompilerException e) {
					e.printStackTrace();
				}
				
			} catch (FileNotFoundException e) {
				System.out.println("No file to read");
			}
		}
		// if there is an incorrect extension then errors
		else {
			String message = "incorrect file extension!";

			throw new CompilerException(message);

		}

		// 1 check to make sure args
		// 2 check to make sure file has mkd extension using endsWith(".mkd")
		// 3 initialize vars
		// 4 call the lexical analyzer for first token
		// 5 call the start state of the parser i.e. document();

		// ... lexer and parser do their thang

		// 6 call the semantic analyzer when code returns or in syntax analyzer
		// 7 write output file
		// 8. clean up

	}

}
